package com.m3958.firstgwt.server.accesschecker;

import com.m3958.firstgwt.server.dao.WorkFlowProjectDao;
import com.m3958.firstgwt.server.model.WorkFlowProject;
import com.m3958.firstgwt.shared.type.SmartParameterName;



public class WorkFlowProjectChecker extends BaseChecker<WorkFlowProject> {

	@Override
	protected boolean canAdd() {
		return false;
	}

	@Override
	protected boolean canCustom() {
		return false;
	}

	@Override
	protected boolean canFetch() {
		switch (getSubOpName()) {
		case NAMED_QUERY:
			String qn = reqPs.getStringValue(SmartParameterName.NAMED_QUERY_NAME);
			if(WorkFlowProject.NamedQueries.FIND_BY_USER_ID.equals(qn)){
				if(su.isLogined()){
					return true;
				}else{
					return false;
				}
			}else if(WorkFlowProject.NamedQueries.FIND_PROJECTS_BY_UUID.equals(qn)){
				String uuid = reqPs.getStringValue("_itemId",""); 
				if(uuid.isEmpty()){
					return false;
				}else{
					if(uuid.length() != 36){
						return false;
					}else{
						WorkFlowProjectDao wfwdao = injector.getInstance(WorkFlowProjectDao.class);
						WorkFlowProject wfp = wfwdao.findByUUID(uuid);
						if(wfp == null)return false;
						if("public".equals(wfp.getShareType()) || "public-editable".equals(wfp.getShareType())){
							return true;
						}
					}
				}
			}

		default:

		}
		return false;
	}

	@Override
	protected boolean canMyRpc() {
		return false;
	}

	@Override
	protected boolean canRemove() {
		return false;
	}

	@Override
	protected boolean canUpdate() {
		return false;
	}

}
